/*
 * main.cpp
 *
 *  Created on: 17 Sep, 2017
 *      Author: buffon
 */
#include "MemAudio.h"
//#include "TimerTask.h"
#include "RtmpAudio.h"

int main(){

	MemAudio* pMemAudio = new MemAudio();
	if(!pMemAudio){
		cout << "create MemAudio failed!"<<endl;
		return 0;
	}

	RtmpAudio* pRtmpAudio = new RtmpAudio(pMemAudio);
	if(!pRtmpAudio){
		cout << "create RtmpAudio failed!"<<endl;
		return 0;
	}

//	TimerTask* pTimerTask = new TimerTask(pMemAudio,2,4,"http://mmkyf.maimaicn.com/mmjmanager/yaotv/tvUpload.action");
//	if(!pTimerTask){
//			cout << "create TimerTask failed!"<<endl;
//			return 0;
//	}
#ifdef _WIN32
	DWORD		threadIds[2];
#else
	pthread_t	threadIds[2];
#endif
//	threadIds[0] = pTimerTask->GetThreadId();
	threadIds[1] = pRtmpAudio->GetThreadId();

	pRtmpAudio->StartThread();
//	pTimerTask->StartThread();

	char ch;
	bool bRunning = true;
	cout << "enter 'q'  to quit..."<<endl;
	while(bRunning){
		cin >> ch;
		if(ch == 'q' || ch== 'Q'){
			bRunning = false;
			pRtmpAudio->StopThread();
//			pTimerTask->StopThread();
			//waiting childs to stop
#ifdef _WIN32

#else
//	pthread_join(threadIds[0],NULL);
	pthread_join(threadIds[1],NULL);
#endif

//			if(pTimerTask){
//				delete pTimerTask;
//				pTimerTask = NULL;
//			}
			if(pRtmpAudio){
				delete pRtmpAudio;
				pRtmpAudio = NULL;
			}

			if(pMemAudio){
				delete pMemAudio;
				pMemAudio = NULL;
			}
		}
	}
	return 0;
}
